<?php
// +----------------------------------------------------------------------
//            -------------------------
//           /   / ----------------\  \
//          /   /             \  \
//         /   /              /  /
//        /   /    /-------------- /  /
//       /   /    /-------------------\  \
//      /   /                   \  \
//     /   /                     \  \
//    /   /                      /  /
//   /   /      /----------------------- /  /
//  /-----/      /---------------------------/
// +----------------------------------------------------------------------
// | Copyright (c) 2016 http://baimifan.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: Sage 2016/4/19  14:05
// +----------------------------------------------------------------------
namespace Wechat\Controller;
use Think\Controller;
// 引用class文件夹对应的类
require_once COMMON_PATH . 'BarCode/class/BCGFontFile.php';
require_once COMMON_PATH . 'BarCode/class/BCGColor.php';
require_once COMMON_PATH . 'BarCode/class/BCGDrawing.php';

// 条形码的编码格式
require_once COMMON_PATH . 'BarCode/class/BCGcode39.barcode.php';

Class VipController extends BaseController{
    //会员管理
    function index(){
        $user_id=session("user_id");
        $User=M("User");
        $d=$User->where("user_id=$user_id")->field("nickname,headimgurl")->find();
        $Card=M("Card");
        $dc=$Card->where("user_id=$user_id")->find();

        $this->assign("dc",$dc);
        $this->assign("d",$d);
        $this->display();
    }

	function getBarcode(){
		header('Content-Type:text/html;charset=utf-8');
        $card_id=I('get.card_id')==""?'NULL':I('get.card_id');

        // 加载字体大小
        $font = new \BCGFontFile(COMMON_PATH.'BarCode/font/Arial.ttf', 18);

        //颜色条形码
        $color_black = new \BCGColor(0, 0, 0);
        $color_white = new \BCGColor(255, 255, 255);

        $drawException = null;
        try {
            $code = new \BCGcode39();
            $code->setScale(2);
            $code->setThickness(30); // 条形码的厚度
            $code->setForegroundColor($color_black); // 条形码颜色
            $code->setBackgroundColor($color_white); // 空白间隙颜色
            $code->setFont($font); //
            $code->parse($card_id); // 条形码需要的数据内容
        } catch(Exception $exception) {
            $drawException = $exception;
        }

        //根据以上条件绘制条形码
        $drawing = new \BCGDrawing('', $color_white);
        if($drawException) {
            $drawing->drawException($drawException);
        } else {
            $drawing->setBarcode($code);
            $drawing->draw();
        }
        // 生成PNG格式的图片
        header('Content-Type: image/png');
        $drawing->finish(\BCGDrawing::IMG_FORMAT_PNG);
	}
}